import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';

export default function beforeTableEdit(areaCode, key, model) {
    const {orgVal, func_type} = this.props;
    const that = this;
    let postData = {
        areaCode,
        func_type,
        pk_org: orgVal.refpk,
        key,
        model: {areacode: areaCode, rows: [model]}
    };

    return proFetch({
        url: '/nccloud/hrtrn/pub/RecordsPsntransRecBeforeEditAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success && res.data.editable) {
                if (res.data.refParam) {
                    let meta = that.props.meta.getMeta();
                    let editItem = meta[areaCode].items.find(item => item.attrcode === key);
                    editItem.queryCondition = function () {
                        return res.data.refParam
                    };
                    that.props.meta.setMeta(meta);
                } else {
                    let meta = that.props.meta.getMeta();
                    let editItem = meta[areaCode].items.find(item => item.attrcode === key);
                    if(editItem.itemtype === 'refer') {
                        editItem.queryCondition = function () {
                            return {
                                pk_org: orgVal.refpk
                            }
                        };
                        that.props.meta.setMeta(meta);
                    }
                    
                }
                return true;
            }
        });
}
